package com.bw.zg3park2212.task

import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.blankj.utilcode.util.TimeUtils
import com.bw.base.entity.DataEntity
import com.bw.base.mvvm.BaseActivity
import com.bw.zg3park2212.adpter.TaskAdpter
import com.bw.zg3park2212.databinding.ActivityTaskBinding
import dagger.hilt.android.AndroidEntryPoint
import java.text.SimpleDateFormat
import java.util.Calendar

@Route(path = "/app/TaskActivity")
@AndroidEntryPoint
class TaskActivity : BaseActivity<ActivityTaskBinding,TaskViewModel>() {
    lateinit var taskAdpter: TaskAdpter
    lateinit var dataAdpter: DataAdpter
    var list= mutableListOf<DataEntity>()
    override fun intitView() {
        taskAdpter= TaskAdpter()
        dataAdpter= DataAdpter()
        binding.rvTask.layoutManager=LinearLayoutManager(this)
        binding.rvTask.adapter=taskAdpter
        viewmodel.gettaskstutse("0")
        binding.tvData.setText(SimpleDateFormat("yyyy-MM").format(System.currentTimeMillis()))
        var calendar=Calendar.getInstance()
        var week=calendar.get(Calendar.DAY_OF_WEEK)
        for (i in -(week-1) .. -(week-1)+6){
            calendar=Calendar.getInstance()
            calendar.add(Calendar.DAY_OF_MONTH,i)
            var day=calendar.get(Calendar.DAY_OF_MONTH)
            var weeek1=TimeUtils.getChineseWeek(calendar.time).substring(1,2)
            list.add(DataEntity(weeek1,day.toString(),if (i==0) true else false))
        }
        binding.rvData.adapter=dataAdpter
        binding.rvData.layoutManager=GridLayoutManager(this,7)
        dataAdpter.addData(list)
        taskAdpter.setOnItemClickListener { adapter, view, position ->
            ARouter.getInstance().build("/app/TaskXiangActivity")
                .withSerializable("task",taskAdpter.data[position] )
                .navigation()
        }
    }

    override fun intitData() {
        viewmodel.taskstutseSuccse.observe(this){
            taskAdpter.data.clear()
            taskAdpter.addData(it)
            taskAdpter.notifyDataSetChanged()
        }
    }

}